﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace GordonKristan.codeclean
{
	public partial class OptionsPageStyleControl : UserControl
	{
		private OptionsPageStyle OptionsPage { get; set; }

		/// <summary>
		/// Default initializer.
		/// </summary>
		public OptionsPageStyleControl()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Custom constructor to assign an options page object.
		/// </summary>
		/// <param name="op">Options page associated with this control.</param>
		public OptionsPageStyleControl(OptionsPageStyle op)
			: this()
		{
			OptionsPage = op;
			//Set initial state of checkboxes
			RemoveWhitespaceAtBottomCheckbox.Checked = OptionsPage.RemoveWhitespaceAtBottom;
			RemoveWhitespaceAtTopCheckbox.Checked = OptionsPage.RemoveWhitespaceAtTop;
			RemoveWhitespaceAtBottomExceptNewlineCheckbox.Checked = OptionsPage.RemoveWhitespaceAtBottomExceptNewline;
			RemoveWhitespaceEndLineCheckbox.Checked = OptionsPage.RemoveWhitespaceEndLine;
			RemoveConsecutiveBlankLinesCheckbox.Checked = OptionsPage.RemoveConsecutiveBlankLines;
			RemoveBlankBeforeBraceCheckbox.Checked = OptionsPage.RemoveBlankBeforeBrace;
			RemoveBlankAfterBraceCheckbox.Checked = OptionsPage.RemoveBlankAfterBrace;
			InsertLineAfterMethod.Checked = OptionsPage.InsertLineAfterMethod;
		}	

		/// <summary>
		/// Handles the event where the user changes the remove whitespace at top checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveWhitespaceAtTopCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveWhitespaceAtTop = RemoveWhitespaceAtTopCheckbox.Checked;
		}

		/// <summary>
		/// Handles the event where the user changes the remove whitespace at bottom checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveWhitespaceAtBottomCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveWhitespaceAtBottom = RemoveWhitespaceAtBottomCheckbox.Checked;
			RemoveWhitespaceAtBottomExceptNewlineCheckbox.Enabled = OptionsPage.RemoveWhitespaceAtBottom;
		}

		/// <summary>
		/// Handles the event where the user changes the remove whitespace at bottom except newline checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveWhitespaceAtBottomExceptNewlineCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveWhitespaceAtBottomExceptNewline = RemoveWhitespaceAtBottomExceptNewlineCheckbox.Checked;
		}

		/// <summary>
		/// Handles the event where the user changes the remove end of line whitespace checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveWhitespaceEndLineCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveWhitespaceEndLine = RemoveWhitespaceEndLineCheckbox.Checked;
		}

		/// <summary>
		/// Handles the event where the user changes the remove multiple blank lines checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveConsecutiveBlankLinesCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveConsecutiveBlankLines = RemoveConsecutiveBlankLinesCheckbox.Checked;
		}

		/// <summary>
		/// Handles the event where the user changes the remove blank line after brace checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveBlankAfterBraceCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveBlankAfterBrace = RemoveBlankAfterBraceCheckbox.Checked;
		}

		/// <summary>
		/// Handles the event where the user changes the remove blank line before brace checkbox.
		/// </summary>
		/// <param name="sender">Source of event</param>
		/// <param name="e">Event Data</param>
		private void RemoveBlankBeforeBraceCheckbox_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.RemoveBlankBeforeBrace = RemoveBlankBeforeBraceCheckbox.Checked;
		}

		/// <summary>
		/// Handles the even where the user changes the insert line after method checkbox.
		/// </summary>
		/// <param name="sender">SOurce of event</param>
		/// <param name="e">Event Data</param>
		private void InsertLineAfterMethod_CheckedChanged(object sender, EventArgs e)
		{
			OptionsPage.InsertLineAfterMethod = InsertLineAfterMethod.Checked;
		}
	}
}
